package pl.edu.pk.mech.kkbus.repository;

import static pl.edu.pk.mech.kkbus.staticstrings.HistoryLogProperty.HISTORY_LOG_DATE;
import static pl.edu.pk.mech.kkbus.staticstrings.HistoryLogProperty.HISTORY_LOG_ID_USER;
import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_HISTORY_LOG;

import java.util.ArrayList;
import java.util.List;

import pl.edu.pk.mech.kkbus.datastore.common.SynchronizeCommon;
import pl.edu.pk.mech.kkbus.model.HistoryLog;
import pl.edu.pk.mech.kkbus.model.Pojo;

import com.google.appengine.api.datastore.Entity;

public class HistoryLogDAO extends BaseDAO{

	@Override
	public void fillProperty(Pojo pojo, Entity entity) {
		HistoryLog historyLog = (HistoryLog) pojo;
		  entity.setProperty(HISTORY_LOG_ID_USER, historyLog.getIdUser());
		  entity.setProperty(HISTORY_LOG_DATE, historyLog.getDate());		
	}
	
	public List<HistoryLog> getHistoryLogByIdUser(String idUser) {
		  List<HistoryLog> temp = new ArrayList<HistoryLog>();
		  Iterable<Entity> entityList = SynchronizeCommon.listEntities(NAME_ENTITY_HISTORY_LOG, HISTORY_LOG_ID_USER, idUser);
		  for (Entity entity : entityList) {
			  temp.add(new HistoryLog(entity));
		  }
		  return temp;
	}
}
